package com.jprocms.module.cms.convert;

import com.jpro.framework.common.pojo.PageResult;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.pagehelper.Page;
import org.mapstruct.Mapper;
import org.mapstruct.MappingConstants;

/**
 * 分页转换工具
 *
 * @author jprocms
 */
@Mapper(componentModel = MappingConstants.ComponentModel.SPRING)
public class PageConverter {

    /**
     * 分页对象转换
     *
     * @param iPage
     * @return
     */
    public PageResult page(IPage iPage) {
        PageResult result = new PageResult();
        result.setList(iPage.getRecords());
        result.setTotal(iPage.getTotal());
        result.setPages(iPage.getPages());
        result.setCurrent(iPage.getCurrent());
        return result;
    }

    /**
     * 分页对象转换
     *
     * @param iPage
     * @return
     */
    public PageResult page(Page iPage) {
        PageResult result = new PageResult();
        result.setList(iPage.getResult());
        result.setTotal(iPage.getTotal());
        result.setPages(new Long(iPage.getPages()));
        result.setCurrent(new Long(iPage.getPageNum()));
        return result;
    }

}
